﻿using System.Collections.ObjectModel;
using System.Windows.Input;
using Microsoft.Practices.Prism.Commands;
using SilverPop.UI.Controls;
using SilverPop.UI.Domain;
using SilverPop.UI.Services;

namespace SilverPop.UI.ViewModels
{
	public class NoteCanvasViewModel
	{
		private readonly INoteDataService _noteData;

		public NoteCanvasViewModel(INoteDataService noteData)
		{
			_noteData = noteData;
			Notes = new ObservableCollection<Note>(_noteData.GetNotes().Notes);

			CanvasClicked = new DelegateCommand<MouseButtonCommandArguments>(OnCanvasClicked);
			DeleteNode = new DelegateCommand<Note>(OnDeleteNode);
		}

		public ObservableCollection<Note> Notes{ get; private set; }

		public ICommand CanvasClicked { get; set; }
		public ICommand DeleteNode { get; set; }

		private void OnCanvasClicked(MouseButtonCommandArguments args)
		{
			NotePage page = _noteData.GetNotes();
			Note newNote = page.AddNewNote(args.Position.X, args.Position.Y);
			Notes.Add(newNote);
		}

		private void OnDeleteNode(Note noteToDelete)
		{
			Notes.Remove(noteToDelete);
		}
	}
}
